package com.ignotus.aifile;

import processing.core.PApplet;

/** 
 * Provides factory methods to construct  a closed path consisting of straight line segments.
 */
public class BezPolygon extends BezShape {

	/**
	 * Constructs a closed polygonal shape from an array of float.
	 * Fill, stroke, and weight are set from their values in the Processing environment. 
	 * The shape will be closed and consist only of straight lines. The last coordinate pair
	 * and the first should be identical for a properly closed polygon (it will be marked
	 * as closed when exported to Adobe Illustrator, regardless).
	 * @param coords   an array of coordinate pairs
	 * @return         a multi-segment line of type BezShape.BEZ_MULTILINE
	 */
	protected BezPolygon(PApplet parent, float[] coords) {
		super(parent);
		if (coords.length < 2) {
			throw new IllegalArgumentException("The array argument must contain at least two values");
		}
		if (0 != coords.length % 2) {
			throw new IllegalArgumentException("The array argument must contain an even number of values");
		}
		this.setIsClosed(true);
		int i = 0;
		this.setStartPoint(coords[i++], coords[i++]);
		while (i < coords.length - 1) {
			this.append(coords[i++], coords[i++]);
		}
		this.setBezType(BezType.BEZ_POLY);
	}


	/**
	 * Constructs a multi-segment line from an array of float.
	 * Fill, stroke, and weight are set from their values in the Processing environment. 
	 * The shape will be open and consist only of straight lines.
	 * @param coords   an array of coordinate pairs
	 * @return         a multi-segment line of type BezShape.BEZ_MULTILINE
	 */
	public static BezPolygon makePolygon(PApplet parent, float[] coords) {
		return new BezPolygon(parent, coords);
	}

}
